package com.huaru.formboot.form.controller;


import com.huaru.formboot.form.entity.Dto.TableData;
import com.huaru.formboot.form.service.TableDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 表单数据表 前端控制器
 * </p>
 *
 * @author wz
 * @since 2021-04-15
 */
@Api(tags = "表单数据相关接口")
@RestController
@RequestMapping("/form/table-data")
public class TableDataController {
    @Autowired
    private TableDataService tableDataService;

    @ApiOperation("表单数据树tableData接口")
    @PostMapping("/getAllTableData")
    public List<TableData> getAllTableData(){
        return tableDataService.getAllTableData();
    }

    @ApiOperation("保存tableData接口")
    @PostMapping("/saveTableData")
    public Integer saveTableData(@RequestBody TableData tableData){
        return tableDataService.saveTableData(tableData);
    }

    @ApiOperation("添加根节点接口")
    @PostMapping("/insertRootNode")
    public Integer insertRootNode(@RequestBody TableData tableData){
        return tableDataService.insertRootNode(tableData);
    }

    @ApiOperation("添加下级节点接口")
    @PostMapping("/insertLowerNode")
    public Integer insertLowerNode(@RequestBody TableData tableData){
        return tableDataService.insertLowerNode(tableData);
    }

    @ApiOperation("根据表单数据id删除数据接口")
    @PostMapping("/deleteTableData")
    public Integer deleteTableData(@RequestBody TableData tableData){
        return tableDataService.deleteTableData(tableData.getTableId() );
    }

    @ApiOperation("编辑表单数据接口")
    @PostMapping("/updateTableData")
    public Integer updateTableData(@RequestBody TableData tableData){
        return tableDataService.updateTableData(tableData);
    }
}

